import java.util.Scanner;
import java.util.Random;
public class A38{
    public static void main(String[] args){
        //1.键盘输入任意字符串,打乱里面的内容
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入字符串");
        String str = sc.next();
        char[] arr = str.toCharArray();
        Random r = new Random();
        for(int i = 0;i < arr.length;i++){
            char temp = arr[i];
            int index = r.nextInt(arr.length);
            arr[i] = arr[index];
            arr[index] = temp;
        }
        String result = new String(arr);
        System.out.println(result);

        //2.生成验证码:4位字母(大小写都可以),1位数字(可以在任意位置)
        char[] arr1 = new char[52];
        for(int i = 0;i < 26;i++){
            arr1[i] = (char)('a'+i);
        }
        for(int i = 26;i < arr1.length;i++){
            arr1[i] = (char)('A'+i-26);
        }
        for(int i = 0;i < arr1.length;i++){
            System.out.print(arr1[i]);
        }
        System.out.println();
        int[] arr2 = new int[10];
        for(int i = 0;i < 10;i++){
            arr2[i] = i;
        }
        //方法一
        char[] arr3 = new char[5];
        for(int i = 0;i < arr3.length-1;i++){
            arr3[i] = arr1[r.nextInt(52)];
        }
        arr3[arr3.length-1] = (char)('0'+arr2[r.nextInt(10)]);//一定要加'0'
        for(int i = 0;i < arr3.length;i++){
            char temp = arr3[i];
            int index = r.nextInt(arr3.length);
            arr3[i] = arr3[index];
            arr3[index] = temp;
        }
        String result1 = new String(arr3);
        System.out.println(result1);
        //方法二
        char[] arr4 = new char[5];
        for(int i = 0;i < arr4.length;i++){
            arr4[i] = arr1[r.nextInt(52)];
        }
        arr4[r.nextInt(arr3.length)] = (char)('0'+arr2[r.nextInt(arr2.length)]);//一定要加'0'
        String result2 = new String(arr4);
        System.out.println(result2);

        //3.给定两个以字符串形式表示的非负整数num1和num2,返回他们的乘积,也表示成字符串形式
        System.out.println("请输入第一个数");
        String num1 = sc.next();
        System.out.println("请输入第二个数");
        String num2 = sc.next();
        //方法一
        System.out.println(multiChar(getMulti(num1,num2)));
        //方法二
        System.out.println(multiChar(getMulti1(num1,num2)));
		
		//4.给你一个字符串 s，由若干单词组成，单词前后用一些空格字符隔开。
		//返回字符中最后一个单词的长度。
		//单词是指仅由字母组成、不包含任何空格字符的最大子字符串。
        System.out.println("请输入一个字符串");
        sc.nextLine();//一定要清空换行符
        String str1 = sc.nextLine();//一定要是nextLine
        System.out.println(getLen(str1));
    }
    public static int getMulti(String num1,String num2){
        int multi1 = 0;
        for(int i = 0;i < num1.length();i++){
            multi1 = multi1*10+(num1.charAt(i)-'0');
        }
        int multi2 = 0;
        for(int i = 0;i < num2.length();i++){//字符串的求长度要加()
            multi2 = multi2*10+(num2.charAt(i)-'0');
        }
        return multi1*multi2;
    }
    public static int getMulti1(String num1,String num2){
        char[] arr1 = num1.toCharArray();
        char[] arr2 = num2.toCharArray();
        int multi1 = 0;
        for(int i = 0;i < arr1.length;i++){//数组的求长度不用加()
            multi1 = multi1*10+(arr1[i]-'0');
        }
        int multi2 = 0;
        for(int i = 0;i < arr2.length;i++){
            multi2 = multi2*10+(arr2[i]-'0');
        }
        return multi1*multi2;
    }
    public static String multiChar(int result){
        StringBuilder sb = new StringBuilder();
        while(result!=0){
            sb.append(result%10);
            result = result/10;
        }
        return sb.reverse().toString();
    }
	public static int getLen(String str){
		int count = 0;
		for(int i = str.length()-1;i>=0;i--){
			if(str.charAt(i) == ' '){
				break;
			}else{
				count++;
			}
		}
		return count;
	}
}